﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace SudokuHelper.Appearance {
    public class CellAppearance {
        #region Private members

        private Color backColor,
                      foreColor,
                      borderColor;

        #endregion

        #region Events

        public event EventHandler Changed;

        #endregion

        #region Properties

        public Color BackColor {
            get { return backColor; }
            set {
                if(backColor!=value){
                    backColor = value;
                    RaiseChanged();
                }
            }
        }

        public Color ForeColor {
            get { return foreColor; }
            set {
                if(foreColor!=value){
                    foreColor = value;
                    RaiseChanged();
                }
            }
        }

        public Color BorderColor {
            get { return borderColor; }
            set {
                if(borderColor!=value){
                    borderColor = value;
                    RaiseChanged();
                }
            }
        }

        #endregion

        #region Constructors

        public CellAppearance() {
        }

        public CellAppearance(Color backColor, Color foreColor, Color borderColor) {
            this.backColor = backColor;
            this.foreColor = foreColor;
            this.borderColor = borderColor;
        }

        #endregion

        #region Utility methods

        public void CopyFrom(CellAppearance other) {
            backColor = other.backColor;
            foreColor = other.foreColor;
            borderColor = other.borderColor;
            RaiseChanged();
        }

        public void Synchronize(CellAppearance other) {
            other.Changed += delegate { CopyFrom(other); };
        }

        private void RaiseChanged() {
            var handler = Changed;
            if (handler != null)
                handler(this, EventArgs.Empty);
        }

        #endregion
    }
}
